package com.baizhi.springmvc.controller;


import com.baizhi.springmvc.entity.Address;
import com.baizhi.springmvc.entity.User;
import com.baizhi.springmvc.service.AddressService;
import com.baizhi.springmvc.service.imp.AddressServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
@Controller
public class AddressController {
    @Autowired
    private  AddressService addressService;

    @RequestMapping("/selectAllAddress")
    public String selectAllAddress(HttpSession session,Map map) {
        User user = (User)session.getAttribute("user");
       List addressList = addressService.selectAllAddress(user.getUser_id());
        map.put("addressList", addressList);
        return "forward:/address/my_address.jsp";
    }
    @RequestMapping("/addAddress")
    public String addAddress(HttpSession session, Address address) {
        User user = (User)session.getAttribute("user");
        address.setUser_id(user.getUser_id());
        address.setStatus(0);
        addressService.insert(address);
        return "redirect:/selectAllAddress.do";
    }
    @RequestMapping("/updateStatus")
    public String updateStatus(HttpSession session,Integer id,Integer status) {
        User user = (User)session.getAttribute("user");
        addressService.updateAllStatus(user.getUser_id());
        addressService.updateStatus(status,id);
        return "redirect:/selectAllAddress.do";
    }
    @RequestMapping("/updateDeleteStatus")
    public String updateDeleteStatus(Integer id) {
        addressService.updateDeleteStatus(id);
        return "redirect:/selectAllAddress.do";
    }


}
